#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
	long long n;
	cin >> n;

	long long p = sqrtl(n) + 1e-6;
	long long k = p * p;
	long long s = p * (p + 1);
	long long t = p * (p + 2);
	long long r = (p + 1) * (p + 1);
		
	long long a[4] = { k, s, t, r };
	int i = 2;
	for (; a[i]>n; --i);
	long long ans = min(n - a[i], a[i + 1] - n);
	cout << ans << endl;
}